package cn.tx.user.feign.fallback;

import cn.tx.pojo.domain.User;
import cn.tx.user.feign.client.UserClient;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 订单客户端feign接口快速失败
 * @author: zealon
 * @since: 2019/7/4
 */
@Component
public class UserClientFallBack implements FallbackFactory<UserClient> {

    private static final Logger logger = LoggerFactory.getLogger(UserClientFallBack.class);

    @Override
    public UserClient create(Throwable cause) {
        return new UserClient() {

            @Override
            public User getUserById(Long id) {
                logger.error("获取用户详情ID[{}] 数量失败：{}", id, cause.getMessage());
                return new User(-1L,"熔断","---熔断---");
            }

            @Override
            public List<User> getListUser(Map<String, Object> params) {
                logger.error("获取用户列表ID[{}] 数量失败：{}", params.toString(), cause.getMessage());
                List<User> userList = new ArrayList<>();
                User User = new User(-1L,"熔断","---熔断---");
                userList.add(User);
                return userList;
            }
        };
    }
}
